package com.player.audio;

import java.io.IOException;
import java.util.ArrayList;

import android.media.MediaPlayer;

public class OdiohMediaPlayer extends MediaPlayer {

	private int currentTrack = 0;
	private int currentSongPosition = 0;
	private String currentSongTitle = null;
	public ArrayList<String> songPathList = new ArrayList<String>();
	public ArrayList<String> songTitleList = new ArrayList<String>();
	
	public String getCurrentSongTitle() {
		return currentSongTitle;
	}
	public void setCurrentSongTitle(String currentSongTitle) {
		this.currentSongTitle = currentSongTitle;
	}
	public ArrayList<String> getSongTitleList() {
		return songTitleList;
	}
	public void setSongTitleList(ArrayList<String> songTitleList) {
		this.songTitleList = songTitleList;
	}
	public ArrayList<String> getSongPathList() {
		return songPathList;
	}
	public void setSongPathList(ArrayList<String> songPathList) {
		this.songPathList = songPathList;
	}
	public int getCurrentTrack() {
		return currentTrack;
	}
	public void setCurrentTrack(int currentTrack) {
		this.currentTrack = currentTrack;
	}
	public int getCurrentSongPosition() {
		return currentSongPosition;
	}
	public void setCurrentSongPosition(int currentSongPosition) {
		this.currentSongPosition = currentSongPosition;
	}
	
	public void nextTrack() {
		try {
			
			reset();
			
			setCurrentTrack((getCurrentTrack()+1) % getSongPathList().size());
			setDataSource(getSongPathList().get( getCurrentTrack() ));
			setCurrentSongTitle(getSongTitleList().get(getCurrentTrack()));
			
			prepare();
			start();
			setCurrentSongPosition(0);
			
		} catch (IllegalArgumentException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IllegalStateException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	
	public void previousTrack() {
		try {
			
			reset();
			
			if(getCurrentTrack() == 0) {
				setCurrentTrack(getSongPathList().size()-1);
			}
			
			else {
				setCurrentTrack((getCurrentTrack()-1));
			}
			
			setDataSource(getSongPathList().get( getCurrentTrack() ));
			setCurrentSongTitle(getSongTitleList().get(getCurrentTrack()));
			
			prepare();
			start();
			setCurrentSongPosition(0);
			
		} catch (IllegalArgumentException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IllegalStateException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	
	 
	 
}
